/*
 * @Author: 悦者生存 1002783067@qq.com
 * @Date: 2023-11-04 17:53:45
 * @LastEditors: 悦者生存 1002783067@qq.com
 * @LastEditTime: 2023-11-20 22:43:28
 * @FilePath: /login-template/client/src/models/user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { getUserList } from '@/services/user';

export default {
  namespace: 'user',
  state: {
    userInfo: {},
    users: [],
  },
  reducers: {
    setState(state: any, { payload }: any) {
      return {
        ...state,
        ...payload,
      };
    },
  },
  effects: {
    *setCurrentUser({ payload }: any, { put }: any) {
      yield put({
        type: 'setState',
        payload: {
          userInfo: payload,
        },
      });
    },
    *getUsers(_action: any, { put, call }: any): any {
      const data = yield call(getUserList);
      yield put({
        type: 'setState',
        payload: {
          users: data,
        },
      });
    },
  },
};
